<?php


namespace app\admin\model\Merchant;


use think\facade\Db;
use think\Model;
use think\model\concern\SoftDelete;

class MerchantModel extends Model
{
    use SoftDelete;
    /**
     * 数据表名
     * @var string
     */
    protected $name = "merchant";
    protected $deleteTime = 'deleted_at';


    /**
     * 根据条件查询多条数据
     * @param $where
     * @return mixed
     * @throws
     */
    public static function getMerchantWhereMore($where)
    {
        $list = Db::name("merchant")->where($where)->select()->toArray();
        return $list;
    }

    /**
     * 统计总数
     * @param $where
     * @return int
     */
    public static function getMerchantCountWhere($where)
    {
        $count = Db::name("merchant")->where($where)->count();
        return $count;
    }

    /**
     * 分页查询
     * @param $page
     * @param $limit
     * @param $where
     * @return mixed
     * @throws
     */
    public static function getMerchantListWhere($page, $limit, $where = [], $field = "*")
    {
        $start = ceil(($page - 1) * $limit);
        $list = Db::name('merchant')->field($field)->where($where)->limit($start, $limit)->select()->toArray();
        return $list;
    }

    /**
     * 添加返回ID
     * @param $data
     * @return int
     */
    public static function addMerchant($data)
    {
        $id = Db::name('merchant')->insertGetId($data);
        return $id;
    }

    /**
     * 更新
     * @param $where
     * @param $save
     * @return int
     * @throws
     */
    public static function updateMerchantWhere($where, $save)
    {
        $flag = Db::name('merchant')->where($where)->update($save);
        return $flag;
    }

    /**
     * 删除
     * @param $where
     * @return int
     * @throws
     */
    public static function delMerchantWhere($where)
    {
        $flag = Db::name('merchant')->where($where)->delete();
        return $flag;
    }

}
